//
//  PageControlBarView
//  tianyaClient
//
//  Created by wangweike on 11-9-27.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PageBarController.h"
#import "CellData.h"
#import "CellImageLabelView.h"
#import "CellImageView.h"
#import "UIView+Custom.h"
#import "tyconsts.h"
#import "Instance.h"

@implementation PageBarController

-(void)constructScrollView:(CGRect)frame
{
    const int columnCount=6;
    
    NSMutableArray* cellDataArray=[[NSMutableArray alloc] initWithCapacity:columnCount];
    
    //返回
    CellData* cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_back.png"];
    cellData.iLabelText=@"返回";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=0;
    [cellDataArray addObject:cellData];
    
    //首页
    cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_first.png"];
    cellData.iLabelText=@"首页";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=1;
    [cellDataArray addObject:cellData];
    
    //上页
    cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_pre.png"];
    cellData.iLabelText=@"上页";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=2;
    [cellDataArray addObject:cellData];
    
    //更多
    cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_more.png"];
    cellData.iLabelText=@"更多";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=3;
    [cellDataArray addObject:cellData];
    
    //下页
    cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_next.png"];
    cellData.iLabelText=@"下页";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=4;
    [cellDataArray addObject:cellData];
    
    //尾页
    cellData=[[[CellData alloc] init] autorelease];
    cellData.iImage=[UIImage imageNamed:@"menu_last.png"];
    cellData.iLabelText=@"尾页";
    cellData.iCellLayout=ECellLayout_LabelBelowImage;
    cellData.iId=5;
    [cellDataArray addObject:cellData];
    
    //ScrollView
    iPageBarView=[[ScrollView alloc] initWithFrame:frame];
    [iPageBarView setColumns:columnCount rows:1];
    [iPageBarView setCellArray:cellDataArray delegate:self];
    [cellDataArray release];
    [iPageBarView setBackgroundImage:[UIImage imageNamed:@"tab_bg.png"]];
    
    //button
    firstButton_=[iPageBarView cellViewAtIndex:1];
    preButton_=[iPageBarView cellViewAtIndex:2];
    nextButton_=[iPageBarView cellViewAtIndex:4];
    lastButton_=[iPageBarView cellViewAtIndex:5];
}

#pragma mark CellViewDelegate
-(void)handleCellEvent:(CellView*)aCellView cellData:(CellData*)aCellData
{
	int idd=aCellData.iId;
	
	switch(idd)
	{
		case 1:
			{
                //首页
				[pageNumberSelectController_ selectFirstPage];
			}
			break;	
		case 2:
			{
                //上页
				[pageNumberSelectController_ switchPrePage];
			}
			break;	
        case 4:
            {
                //下页
                [pageNumberSelectController_ switchNextPage];
            }
			break;	
		case 5:
            {
                //尾页
                [pageNumberSelectController_ selectLastPage];
            }
			break;
		default:
			{
				[super handleCellEvent:aCellView cellData:aCellData];
			}
			break;	
	}
}
@end
